/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgt.supermarket.util;

import java.text.ParseException;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Administrator
 */
public class ServletExtensions {

    public static String getStringParam(HttpServletRequest request, String name) {
        if (request.getParameter(name) != null) {
            return request.getParameter(name);
        } else {
            return "";
        }
    }

    public static long getLongParam(HttpServletRequest request, String name) {
        String s = request.getParameter(name);
        if (s == null || s.equalsIgnoreCase("")) {
            return 0;
        }
        return Converter.toInt(s);

    }

    public static int getIntParam(HttpServletRequest request, String name) {
        String s = request.getParameter(name);
        if (s == null || s.equalsIgnoreCase("")) {
            return 0;
        }
        return Converter.toInt(s);
    }

    public static double getDoubleParam(HttpServletRequest request, String name) {
        String s = request.getParameter(name);
        if (s == null || s.equalsIgnoreCase("")) {
            return 0;
        }
        return Converter.toDouble(s);

    }

    public static Date getDateParam(HttpServletRequest request, String name, String fmt) throws ParseException {
        String s = request.getParameter(name);
        if (s == null) {
            return null;
        }
        return Converter.toDate(s, fmt);
    }

    public static boolean getBooleanParam(HttpServletRequest request, String name) {
        String s = request.getParameter(name);
        if (s != null) {
            return true;
        }
        return false;
    }
}
